import React from "react";
import { useState } from "react";
export default function RadioBase(props) {
  const [value, setValue] = useState(props.defaultValue);
  const onChange = (e, value) => {
    setValue(e.target.value);

    if (e.target.checked) {
      setValue(value);
    } else {
      setValue("");
    }
    props.onChange && props.onChange(value);
  };
  const checkboxes = props.options.map((it) => (
    <label key={it.value}>
      <input
        type="checkbox"
        checked={value === it.value}
        onChange={(e) => {
          onChange(e, it.value);
        }}
      />
      {it.label}
    </label>
  ));
  return checkboxes;
}
